package cn.rumoss.thread;

/**
 * @ClassName TestSync2
 * @Description //TODO
 * @Author HeCG
 * @Date 19-4-11 下午5:52
 */
public class TestSync2 implements Runnable {

    int b = 100;

    synchronized void m1() throws InterruptedException {
        //System.out.println("m1 "+b);
        b = 1000;
        Thread.sleep(500);//6
        System.out.println("b=" + b);
    }

    synchronized void m2() throws InterruptedException {
        //System.out.println("m2 "+b);
        Thread.sleep(250);//5
        b = 2000;
        //System.out.println("m2 "+b);
    }

    public static void main(String[] args) throws InterruptedException {

        TestSync2 tt = new TestSync2();
        Thread t = new Thread(tt);//1
        t.start();//2

        tt.m2();// 3
        System.out.println("main thread b=" + tt.b);

    }

    @Override
    public void run() {
        try{
            m1();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
